package dongshi.daddy.springioc.three.three_two.config;

import org.apache.commons.dbcp2.BasicDataSourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
// 默认扫描当前类所在包以及其子包下的@Component注解
// @ComponentScan(basePackages = { "dongshi.daddy.springioc.three.three_two.*" })
@ComponentScan(basePackages = {"dongshi.daddy.springioc.three.three_two.*"},
        excludeFilters = { @ComponentScan.Filter(classes = {Service.class})})
public class AppConfig {

    @Bean("dataSource")
    public DataSource getDataSource() {
        Properties properties = new Properties();
        properties.setProperty("driver", "com.mysql.jdbc.Driver");
        properties.setProperty("url", "jdbc:mysql://localhost:3306/xxx");
        properties.setProperty("username", "root");
        properties.setProperty("password", "111111");
        DataSource dataSource = null;
        try {
            dataSource = BasicDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataSource;
    }
}
